package com.hui.xiao.xiaohui.res;

import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;

import com.hui.xiao.xiaohui.R;

/**
 * Created by Administrator on 2016/5/29.
 */
public class ValuesResTest extends Activity {
    int[] colors = new int[]{
            R.color.color1, R.color.color2, R.color.color3,
            R.color.color4, R.color.color5, R.color.color6
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.values_res);
        final GridView grid = (GridView) findViewById(R.id.grid);
        BaseAdapter adapter = new BaseAdapter() {
            @Override
            public int getCount() {
                return colors.length;
            }

            @Override
            public Object getItem(int position) {
                return ValuesResTest.this.getResources().getStringArray(R.array.books)[position];
            }

            @Override
            public long getItemId(int position) {
                return position;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                Resources resources = ValuesResTest.this.getResources();
                TextView view = new TextView(ValuesResTest.this);
                view.setText(resources.getStringArray(R.array.books)[position]);
                view.setWidth((int) resources.getDimension(R.dimen.cell_width));
                view.setHeight((int) resources.getDimension(R.dimen.cell_height));
                view.setTextColor(resources.getColor(colors[position]));
                return view;
            }
        };
        grid.setAdapter(adapter);
    }
}
